#pragma once
#include "IFragmentController.h"
#include <mfapi.h>
#include <Mfreadwrite.h>

namespace Microsoft {
	namespace Media {
		namespace FragmentedMediaSink {

			class FragmentBuilder
			{
				DWORD														streamIndex;
				Microsoft::WRL::ComPtr<IMFSinkWriter>						sinkWriter;
				bool														initiated;
				Microsoft::Media::FragmentedMediaSink::Fragment^			fragment;
				bool														isVideo;
				unsigned int												_inputStreamIndex;
				Microsoft::Media::FragmentedMediaSink::IFragmentController^ _fragmentController;
				Microsoft::WRL::ComPtr<IMFMediaType>						_outputMediaType;
				Microsoft::WRL::ComPtr<IMFMediaType>						_inputMediaType;

			public:
				FragmentBuilder(Microsoft::Media::FragmentedMediaSink::IFragmentController^ fragmentController, IMFMediaType* spInputMediaType, unsigned int inputStreamIndex);

				HRESULT WriteSample(_In_ IMFSample* sample);
				HRESULT SendTick(_In_ long long timeStamp);
				HRESULT Flush();
				HRESULT InitializeFragment(_In_ unsigned int fragmentIndex);
				HRESULT TerminateFragment(long long *startTime, long long *endTime);
			};
		}
	}
}